Ext.define('SKJF.view.LAPORAN.RPTHPPEMBELIAN', {
	extend: 'Ext.grid.Panel',
	
	requires	: ['Ext.grid.*',
		'Ext.data.*',
		'Ext.form.field.Number',
		'Ext.form.field.Date',
		'Ext.tip.QuickTipManager'],
	
	itemId		: 'RPTHPPEMBELIAN',
    alias       : 'widget.RPTHPPEMBELIAN',
	//store 		: 's_rpthppembelian',
    
    //title		: 'Daftar Presensi',
    columnLines : true,
    frame		: true,
    margins		: 0,
    
    initComponent: function(){
		var me = this;
		
		var tglmulai_filterField = Ext.create('Ext.form.field.Date', {
			allowBlank : true,
			itemId: 'tglmulai',
			fieldLabel: 'Tgl Mulai',
			labelWidth: 52,
			name: 'TGLMULAI',
			format: 'd M, Y',
			altFormats: 'm,d,Y|Y-m-d',
			value: Ext.Date.subtract(new Date(), Ext.Date.DAY, 1),
			readOnly: false,
			width: 170,
			listeners: {
				'select': function(cb, records, e){
					var filter = "Range";
					var tglmulai_filter = cb.getValue();
					var tglsampai_filter = tglsampai_filterField.getValue();
					// var tglm = tglmulai_filter.format("yyyy-mm-dd");
					// var tgls = tglsampai_filter.format("yyyy-mm-dd");
					me.getStore().proxy.extraParams.tglmulai = tglmulai_filter;
					me.getStore().proxy.extraParams.tglsampai = tglsampai_filter;
					me.getStore().proxy.extraParams.saring = filter;
					me.getStore().load();
				}
			}
		});
		var tglsampai_filterField = Ext.create('Ext.form.field.Date', {
			allowBlank : true,
			itemId: 'tglsampai',
			fieldLabel: 'Tgl Sampai',
			labelWidth: 70,
			name: 'TGLSAMPAI',
			format: 'd M, Y',
			altFormats: 'm,d,Y|Y-m-d',
			value:new Date(),
			readOnly: false,
			width: 190,
			listeners: {
				'select': function(cb, records, e){
					var filter = "Range";
					var tglmulai_filter = tglmulai_filterField.getValue();
					var tglsampai_filter = cb.getValue();
					// var tglm = tglmulai_filter.format("yyyy-mm-dd");
					// var tgls = tglsampai_filter.format("yyyy-mm-dd");
					me.getStore().proxy.extraParams.tglmulai = tglmulai_filter;
					me.getStore().proxy.extraParams.tglsampai = tglsampai_filter;
					me.getStore().proxy.extraParams.saring = filter;
					me.getStore().load();
				}
			}
		});
		
		/* var barang_store = Ext.create('Ext.data.Store', {
			fields: [
                {name: 'NOMOR_PO', type: 'string', mapping: 'NOMOR_PO'},
                {name: 'KODE_BARANG', type: 'string', mapping: 'KODE_BARANG'},
                {name: 'NAMA_BARANG', type: 'string', mapping: 'NAMA_BARANG'},
                {name: 'JENIS_BARANG', type: 'string', mapping: 'JENIS_BARANG'},
                {name: 'JUMLAH', type: 'number', mapping: 'JUMLAH'},
                {name: 'SATUAN', type: 'string', mapping: 'SATUAN'},
                {name: 'HARGA_SATUAN', type: 'string', mapping: 'HARGA_SATUAN'},
                {name: 'TARGET_KIRIM_BRG', type: 'date', mapping: 'TARGET_KIRIM_BRG'},
                {name: 'HSCODE', type: 'string', mapping: 'HSCODE'},
                {name: 'STOCK', type: 'number', mapping: 'STOCK'}
            ],
			proxy: {
				type: 'ajax',
				api: {
					read    : 'c_dodetail/get_barang_from_poclientdet'
					// create	: 'c_mstcustomer/save',
					// update	: 'c_mstcustomer/save',
					// destroy	: 'c_mstcustomer/delete'
				},
				actionMethods: {
					read    : 'POST',
					create	: 'POST',
					update	: 'POST',
					destroy	: 'POST'
				},
				reader: {
					type            : 'json',
					root            : 'data',
					rootProperty    : 'data',
					successProperty : 'success',
					messageProperty : 'message'
				},
				writer: {
					type            : 'json',
					writeAllFields  : true,
					root            : 'data',
					encode          : true
				},
				listeners: {
					exception: function(proxy, response, operation){
						Ext.MessageBox.show({
							title: 'REMOTE EXCEPTION',
							msg: operation.getError(),
							icon: Ext.MessageBox.ERROR,
							buttons: Ext.Msg.OK
						});
					}
				}
			}
			// proxy: {
				// type: 'ajax',
				// url: 'c_dodetail/get_barang_from_poclientdet',
				// reader: {
					// type: 'json',
					// root: 'data'
				// }
			// },
			// autoLoad : true
		}); */
		
    	this.store = Ext.create('SKJF.store.s_rpthppembelian');
		this.plugins=['bufferedrenderer'];
    	this.features = [{
				ftype: 'filters',
				autoReload: true,
				encode: true,
				local: false
			},{
            id: 'group',
            ftype: 'groupingsummary'
			//startCollapsed: false
            //groupHeaderTpl: '{name}'
            //hideGroupedHeader: true,
            //enableGroupingMenu: false
        }];
        this.columns = [
			{
				header: 'NOMOR_LPB',filterable:true,
				dataIndex: 'NOMOR_LPB'
			},{
				header: 'TANGGAL_LPB',filterable:true,
				dataIndex: 'TANGGAL_LPB',
				renderer: Ext.util.Format.dateRenderer('d M, Y')
			},{
				header: 'NAMA_SUPPLIER',filterable:true,
				dataIndex: 'NAMA_SUPPLIER'
			},{
				header: 'NOMOR_FAKTUR',filterable:true,
				dataIndex: 'NOMOR_FAKTUR'
			},{
				header: 'SUB_TOTAL',filterable:true,
				dataIndex: 'SUB_TOTAL',
				align: 'right'
				// renderer: function(value){
					// return Ext.util.Format.currency(value, 'Rp ', 2);
				// }
			},{
				header: 'TOTAL',filterable:true,
				dataIndex: 'TOTAL',
				align: 'right'
				// renderer: function(value){
					// return Ext.util.Format.currency(value, 'Rp ', 2);
				// }
			}];
        
        this.dockedItems = [
			Ext.create('Ext.toolbar.Toolbar', {
				items: [tglmulai_filterField, tglsampai_filterField,{
					xtype: 'fieldcontainer',
					layout: 'hbox',
					defaultType: 'button',
					items: [{
						itemId	: 'btnprint',
						text	: 'Cetak',
						iconCls	: 'icon-print',
						action	: 'print',
						handler	: function(){
							Ext.ux.egen.Printer.mainTitle = 'Laporan Stock Detail';
							Ext.ux.egen.Printer.printAuto = false;
							Ext.ux.egen.Printer.print(me);
							
							console.info(me);
							//Ext.ux.egen.Printer.generateBody(me);
						}
					}]
				}]
			})
		];        
        this.callParent(arguments);
    }

});